package org.zcl.rocketmq.consumer;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.zcl.rocketmq.entity.ConsumerResult;
import org.zcl.rocketmq.entity.MessageObj;

import java.util.Date;


@Component
@Slf4j
public abstract class AbstractFlowConsumer {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;


    /**
     * @return com.dbenefit.flow.vo.ConsumerResult
     * @Author bfd_shipeipei
     * @Description 业务方执行之后返回状态  成功数量  失败数量 等等
     * @Date 17:14 2021/3/18
     * @Param [messageBody]
     **/
    protected abstract ConsumerResult consumer(String messageBody);


    public void doWork(String message) {
        MessageObj messageObj = JSON.parseObject(message, MessageObj.class);
        Date start = new Date();
        log.info("流程ID【{}】，流程实例ID【{}】", messageObj.getFlowId(), messageObj.getInstanceId());
        ConsumerResult result = consumer(message);
        log.info("业务端处理结果【{}】", JSON.toJSONString(result));
    }
}
